package com.zj.study.utils.validation.validator.decimalmin;



import com.zj.study.utils.validation.annotation.constraint.DecimalMin;
import com.zj.study.utils.validation.validator.ConstraintValidator;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

/**
 * @author 谭耀飞
 * @since 2020.12.0
 */
public abstract class AbstractDecimalMinValidator<T> implements
    ConstraintValidator<DecimalMin, T> {

  @Override
  final
  public boolean isValid(@NonNull DecimalMin decimalMin, @Nullable T value) {
    return value == null || compare(decimalMin, value);
  }

  /**
   * 比较值
   *
   * @param decimalMin 最小值
   * @param value      值
   * @return 是否通过校验
   */
  abstract boolean compare(@NonNull DecimalMin decimalMin, @NonNull T value);
}
